<template>
  <div class="vue-box">
    <div class="c-panel">
      <!-- 参数栏 -->
      <div class="c-title">检索参数</div>
      <el-form @submit.native.prevent class="conditional_filter">
        <sa-item v-model="p.search" type="text" name="模糊搜索" />
        <sa-item v-model="p.type" type="enum" jtype="4" :jv="dims.ADS_TYPE" name="广告类型" :def="{}" :clearable="true" />
        <sa-item v-model="p.status" type="enum" jtype="4" :jv="dims.AUDIT_STATUS" name="审核状态" :def="{}"
          :clearable="true" />
        <div class="c-item">
          <el-button type="primary" icon="el-icon-search" @click="p.current = 1; f5()">查询</el-button>
        </div>
      </el-form>
      <!-- ------------- 快捷按钮 ------------- -->
      <sa-item type="fast-btn" show="get,delete,reset" />
      <!-- 数据列表 -->
      <el-table ref="data-table" class="data-table" :data="dataList" border>
        <sa-td type="selection" width="45px" />
        <sa-td type="text" name="序号" prop="id" width="80px" />
        <sa-td type="text" name="广告名" prop="name" />
        <sa-td type="text" name="识别码" prop="code" />
        <sa-td type="enum" name="广告定位" prop="spaceId" :jv="dims.ADS_LOCATION_ID_NAME" />
        <sa-td type="enum" name="广告类型" prop="type" :jv="dims.ADS_TYPE" />
        <sa-td type="datetime" name="申请时间" prop="applyTime" width="160px" />
        <sa-td type="enum" name="审核状态" prop="status" :jv="dims.AUDIT_STATUS" width="100px" />
        <sa-td name="操作" width="140px" fixed="right">
          <template slot-scope="s">
            <el-button type="text" @click="getInfo(s.row)">
              查看
            </el-button>
            <el-button type="text" @click="audit(s.row.id, 1)" v-if="s.row.status === 0">
              通过
            </el-button>
            <el-button type="text" @click="audit(s.row.id, 2)" v-if="s.row.status === 0">
              拒绝
            </el-button>
          </template>
        </sa-td>
      </el-table>
      <!-- 分页 -->
      <div v-if="dataCount">
        <sa-item type="page" :curr.sync="p.current" :size.sync="p.size" :total="dataCount" @change="f5()" />
      </div>
    </div>
  </div>
</template>

<script>
import sa from '@/sa-frame/sa';
export default {
  name: 'ads-apply-list',
  data() {
    return {
      // 查询参数
      p: {
        current: 1,
        size: 10,
        search: null,
        status: null,
        type: null,
      },
      dataCount: null,
      // 数据集合
      dataList: [],
      // 字典
      dims: sa.$sys.getCurd(),
      options: {},
    }
  },
  created: function () {
    this.f5();
    sa.onInputEnter();
  },
  methods: {
    // 刷新
    f5: function () {
      sa.ajax('/ads/apply/getList', sa.removeNull(this.p), function (res) {
        this.dataList = res.data;
        this.dataCount = res.dataCount;
        // 刷新表格高度
        sa.f5TableHeight();
      }.bind(this), { type: "post" });
    },
    // 删除
    del: function (data) {
      sa.confirm('是否删除，此操作不可撤销', function () {
        sa.ajax('/ads/apply/delete', { id: data.id }, function (res) {
          sa.ok(res.msg);
          this.f5();
        }.bind(this), { type: 'get' })
      }.bind(this));
      sa.f5TableHeight();		// 刷新表格高度
    },
    // 批量删除
    deleteByIds() {
      // 获取选中元素的id列表
      let selection = this.$refs['data-table'].selection;
      let ids = sa.getArrayField(selection, 'id');
      if (selection.length == 0) {
        return sa.msg('请至少选择一条数据')
      }
      // 提交删除
      sa.confirm('是否批量删除选中数据？此操作不可撤销', function () {
        sa.ajax('/ads/apply/deleteByIds', { ids: ids }, function (res) {
          sa.ok(res.msg);
          this.f5()
        }.bind(this), { type: "post" })
      }.bind(this));
    },
    // 查看 - 根据选中的
    getBySelect: function () {
      var selection = this.$refs['data-table'].selection;
      if (selection.length === 0) {
        return sa.msg('请至少选择一条数据')
      }
      this.getInfo(selection[0]);
    },

    // 查看详情
    getInfo: function (data) {
      sa.showModel('详情', () => import('./info'), data);
    },

    // 审核操作
    audit(id, status) {
      sa.ajax('/ads/apply/audit', { id: id, status: status }, function (res) {
        if (res.code === 200) {
          this.f5();
        }
      }.bind(this), { type: 'get' });
    },
  },
}
</script>

<style scoped>
.stags {
  display: flex;
  justify-content: start;

  span {
    margin-left: 2px;
  }
}
</style>
